package app.cn.com.school.activity

import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.View
import app.cn.com.school.R
import app.cn.com.school.adapter.MyViewPagerAdapter
import app.cn.com.school.databinding.ActivityOrdersListBinding
import app.cn.com.school.fragment.NewsFragment
import app.cn.com.school.fragment.OrdersFragment

class OrdersListActivity : BaseActivity<ActivityOrdersListBinding>() {
    override fun initBindingVar() {
    }

    override fun initTitle() {
        binding.titlebar.back.setOnClickListener { finish() }
    }

    private var fragemnts = ArrayList<Fragment>()
    private val titles = arrayOf("全部", "待付款", "待发货", "待收货", "待评价")
    private val titlesColl = arrayOf("商品", "店铺", "二手")
    private val titlesScore = arrayOf("已使用", "未使用")
    private var adapter: MyViewPagerAdapter? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initBinding(R.layout.activity_orders_list)
        initView()
    }

    private fun initView() {
        var type = this.intent.getStringExtra("type").toInt()
        when (type) {
            0 -> {
                binding.titlebar.title.text = "我的收藏"
                fragemnts.add(NewsFragment().newInstance(0))
                fragemnts.add(NewsFragment().newInstance(1))
                fragemnts.add(NewsFragment().newInstance(2))
                adapter = MyViewPagerAdapter(supportFragmentManager, fragemnts, titlesColl)
                binding.tabViewpager.adapter = adapter
                binding.orderTab.setupWithViewPager(binding.tabViewpager)
                binding.orderTab.setTabsFromPagerAdapter(adapter)
            }
            1 -> {
                binding.titlebar.title.text = "我的订单"
                fragemnts.add(OrdersFragment().newInstance(0))
                fragemnts.add(OrdersFragment().newInstance(1))
                fragemnts.add(OrdersFragment().newInstance(2))
                fragemnts.add(OrdersFragment().newInstance(3))
                fragemnts.add(OrdersFragment().newInstance(4))
                adapter = MyViewPagerAdapter(supportFragmentManager, fragemnts, titles)
                binding.tabViewpager.adapter = adapter
                binding.orderTab.setupWithViewPager(binding.tabViewpager)
                binding.orderTab.setTabsFromPagerAdapter(adapter)
                var set = this.intent.getStringExtra("set").toInt()
                binding.orderTab.getTabAt(set)!!.select()
            }
            2 -> {
                binding.titlebar.title.text = "我的折扣卷"
                fragemnts.add(NewsFragment().newInstance(0))
                fragemnts.add(NewsFragment().newInstance(1))
                adapter = MyViewPagerAdapter(supportFragmentManager, fragemnts, titlesScore)
                binding.tabViewpager.adapter = adapter
                binding.orderTab.setupWithViewPager(binding.tabViewpager)
                binding.orderTab.setTabsFromPagerAdapter(adapter)
            }
        }
    }
}
